<?php
/**
 * StatZone default controller
 * 
 * @package    USS.StatZone
 * @subpackage Components
 * @link www.ugenix.co.za www.statzone.co.za
 * @license		Commercial
 * @author Salie Hendricks
 */


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );

/**
 * Clubs View
 *
 * @package    USS.StatZone
 * @subpackage Components
 */
class StatZoneViewClubs extends JView
{
	function setClubsToolbar()
	{
		JToolBarHelper::title(   JText::_( 'StatZone Club Manager' ), 'generic.png' );
        JToolBarHelper::publishList();
		JToolBarHelper::unpublishList();
		JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
	}
    
    function setSingleClubToolbar()
	{
		$task = JRequest::getVar( 'task', '', 'method', 'string');

		JToolBarHelper::title( $task == 'add' ? JText::_( 'Clubs' ) . ': <small><small>[ '. JText::_( 'New' ) .' ]</small></small>' : JText::_( 'Club' ) . ': <small><small>[ '. JText::_( 'Edit' ) .' ]</small></small>', 'generic.png' );
		JToolBarHelper::save( 'save' );
		JToolBarHelper::apply('apply');
		JToolBarHelper::cancel( 'cancel' );
		//JToolBarHelper::help( 'screen.banners.edit' );
	}
    
    function singleClub( &$row, &$lists,$name )
	{
		StatZoneViewClubs::setSingleClubToolbar();
		JRequest::setVar( 'hidemainmenu', 1 );
        $contentlink		= JRoute::_( 'index.php?option=com_content&sectionid=-1&task=edit&cid[]='. $row->contentid );
        
		//JFilterOutput::objectHTMLSafe( $row, ENT_QUOTES, 'customclubcode' );
		?>
		<script language="javascript" type="text/javascript">
		<!--
		
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == 'cancel') {
				submitform( pressbutton );
				return;
			}
			// do field validation
			if (form.name.value == "") {
				alert( "<?php echo JText::_( 'You must provide a club name.', true ); ?>" );
			} 
			else if ( getSelectedValue('adminForm','id') == 0 ) {
				alert( "<?php echo JText::_( 'Please select a province.', true ); ?>" );
			} 
          else {
				submitform( pressbutton );
			}
		}
		//-->
		</script>
		<form action="index.php" method="post" name="adminForm">

		<div class="col100">
			<fieldset class="adminform">
				<legend><?php echo JText::_( 'Details' ); ?></legend>

				<table class="admintable">
				<tbody>
					<tr>
						<td width="20%" class="key">
							<label for="name">
								<?php echo JText::_( 'Name' ); ?>:
							</label>
						</td>
						<td width="80%">
							<input class="inputbox" type="text" name="name" id="name" size="50" value="<?php echo $name;?>" />
						</td>
					</tr>
					<tr>
						<td width="20%" class="key">
							<label for="alias">
								<?php echo JText::_( 'Province' ); ?>:
							</label>
						</td>
						<td width="80%">
							<?php echo $lists['provinceid']; ?>
						</td>
					</tr>
                    <tr>
						<td width="20%" class="key">
							<label for="alias">
								<?php echo JText::_( 'Content ID' ); ?>:
							</label>
						</td>
						<td width="80%">
                            <input class="inputbox" type="text" name="contentid" id="contentid" size="50" value="<?php echo $row->contentid; ?>" />
						</td>
					</tr>
                     <tr>
						<td width="20%" class="key">
							<label for="alias">
								
							</label>
						</td>
						<td width="80%">
                            <a href=<?php echo $contentlink; ?>><?php echo JText::_( 'Go to content link' ); ?></a>
						</td>
					</tr>
					
					
				</tbody>
				</table>
			</fieldset>
		</div>
		<div class="clr"></div>

		<input type="hidden" name="c" value="club" />
		<input type="hidden" name="option" value="com_statzone" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
		<?php
	}
    
    function clubs( &$rows, &$pageNav, &$lists )
    {
        StatZoneViewClubs::setClubsToolbar();
        $user =& JFactory::getUser();
		JHTML::_('behavior.tooltip');
        ?>
		<form action="index.php?option=com_statzone" method="post" name="adminForm">
		<table>
        	<tr>
                <td align="left" width="100%">
                    <?php echo JText::_( 'Filter' ); ?>:
                    <input type="text" name="search" id="search" value="<?php echo $lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
                    <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
                    <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_provid').value='0';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_( 'Filter Reset' ); ?></button>
                </td>
                <td nowrap="nowrap">
                    <?php
                    echo $lists['filter_provid'];
                    echo $lists['state'];
                    ?>
                </td>
		    </tr>
		</table>

        <table class="adminlist">
			<thead>
				<tr>
					<th width="2%">
						<?php echo JText::_( 'Num' ); ?>
					</th>
					<th width="2%">
						<input type="checkbox" name="toggle" value=""  onclick="checkAll(<?php echo count( $rows ); ?>);" />
					</th>
					<th nowrap="nowrap" class="title">
						<?php echo JHTML::_('grid.sort',  'Name', 'content.title', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
					<th width="10%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'Province', 'province_name', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
					<th width="10%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'Content ID', 'c.contentid', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'Published', 'c.showClub', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
                    <th width="1%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'ID', 'c.id', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="13">
						<?php echo $pageNav->getListFooter(); ?>
					</td>
				</tr>
			</tfoot>
			<tbody>
			<?php
			$k = 0;
			for ($i=0, $n=count( $rows ); $i < $n; $i++) {
				$row = &$rows[$i];

				$row->id	= $row->id;
				$link		= JRoute::_( 'index.php?option=com_statzone&c=club&task=edit&cid[]='. $row->id );
                $contentlink		= JRoute::_( 'index.php?option=com_content&sectionid=-1&task=edit&cid[]='. $row->contentid );
                
				if( $row->imptotal <= 0 ) {
					$row->imptotal	=  JText::_('unlimited');
				}

				$row->published = $row->state;//$row->showClub;
				$published		= JHTML::_('grid.published', $row, $i );
				$checked		= JHTML::_('grid.checkedout',   $row, $i );
				?>
				<tr class="<?php echo "row" . $k; ?>">
					<td align="center">
						<?php echo $pageNav->getRowOffset($i); ?>
					</td>
					<td align="center">
						<?php echo $checked; ?>
					</td>
					<td>
    					<span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit' );?>::<?php echo $row->name; ?>">
                			<a href="<?php echo $link; ?>">
								<?php echo $row->name; ?></a>
						</span>
					</td>
					<td align="center">
						<?php echo $row->province_name;?>
					</td>
					<td align="center">
						<a href="<?php echo $contentlink;?>">
                            <?php echo $row->contentid;?></a>
					</td>
					<td align="center">
						<?php echo $published;?>
					</td>
					<td align="center">
						<?php echo $row->id; ?>
					</td>
				</tr>
				<?php
				$k = 1 - $k;
			}
			?>
			</tbody>
			</table>

		<input type="hidden" name="c" value="club" />
		<input type="hidden" name="option" value="com_statzone" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $lists['order']; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $lists['order_Dir']; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
		<?php
    }
}
